using System;
using System.Globalization;
using System.Windows.Data;
using WPFTemplateLib.WpfConverters.Core;

/*
 * 源码已托管：https://gitee.com/dlgcy/WPFTemplate
 */
namespace WPFTemplateLib.WpfConverters
{
    /// <summary>
    /// [转换器] 增加 double 值(参数传要增加的数值，double 类型)
    /// </summary>
    public class AddDoubleConverter : ValueConverterBase
    {
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			string logPrefix = $"[{nameof(AddDoubleConverter)}]";

			if (string.IsNullOrWhiteSpace(parameter + ""))
			{
				//throw new ArgumentNullException(nameof(parameter), "parameter can not be null or empty");
				Console.WriteLine($"{logPrefix} parameter can not be null or empty");
			}

			if (!double.TryParse(parameter + "", out double addValue))
			{
				//throw new ArgumentException("parameter must be double type", nameof(parameter));
				Console.WriteLine($"{logPrefix} parameter must be double type");
			}

			if (!double.TryParse(value + "", out double originValue))
			{
				//throw new ArgumentException("value must can be convert to double type", nameof(value));
				Console.WriteLine($"{logPrefix} value must can be convert to double type");
			}

			double result = originValue + addValue;

			return result;
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			return Binding.DoNothing;
		}
    }
}
